local liaoshi = fk.CreateSkill{
  name = "pegasus__liaoshi",
}

Fk:loadTranslationTable{
  ["pegasus__liaoshi"] = "料势",
  [":pegasus__liaoshi"] = "出牌阶段限一次，或当你受到伤害后，你可以移动场上一张牌，本回合与之花色相同的牌被使用时，你摸一张牌。",

  ["#pegasus__liaoshi1"] = "料势：你可以移动场上一张牌，请选择移动来源角色（第一步）",
  ["#pegasus__liaoshi2"] = "料势：你可以移动场上一张牌，请选择接受牌的角色（第二步）",
  ["#pegasus__liaoshi-trigger"] = "料势：你可以移动场上一张牌（选择两名角色）",

  ["@pegasus__liaoshi-turn"] = "料势",
}

liaoshi:addEffect("active", {
  anim_type = "control",
  can_use = function (self, player)
    return player:usedSkillTimes(liaoshi.name, Player.HistoryPhase) == 0
  end,
  prompt = function (self, player, selected_cards, selected_targets)
    if #selected_targets == 0 then
      return "#pegasus__liaoshi1"
    end
    return "#pegasus__liaoshi2"
  end,
  card_num = 0,
  target_num = 2,
  card_filter = Util.FalseFunc,
  target_filter = Util.TrueFunc,
  feasible = function (self, player, selected)
    return #selected == 2 and (selected[1]:canMoveCardsInBoardTo(selected[2]) or selected[1]:canMoveCardsInBoardTo(selected[2]))
  end,
  on_use = function (self, room, effect)
    local player = effect.from
    local tos = effect.tos
    local move = room:askToMoveCardInBoard(player, {
      target_one = tos[1],
      target_two = tos[2],
      skill_name = liaoshi.name,
    })
    if player.dead then return end

    room:addTableMarkIfNeed(player, "@pegasus__liaoshi-turn", move.card:getSuitString(true))
  end
})

liaoshi:addEffect(fk.Damaged, {
  anim_type = "masochism",
  can_trigger = function (self, event, target, player, data)
    return player == target and player:hasSkill(liaoshi.name)
  end,
  on_trigger = function (self, event, target, player, data)
    player.room:askToUseActiveSkill(player, {
      skill_name = liaoshi.name,
    })
  end,
})

liaoshi:addEffect(fk.CardUsing, {
  anim_type = "drawcard",
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill(liaoshi.name, true) and table.contains(player:getTableMark("@pegasus__liaoshi-turn"), data.card:getSuitString(true))
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    player:drawCards(1, liaoshi.name)
  end
})

return liaoshi